import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router';
import { User } from 'src/app/user';
import { TestService } from 'src/app/test.service';
import { NgForm } from '@angular/forms';

@Component({
  selector: 'app-useredit',
  templateUrl: './useredit.component.html',
  styleUrls: ['./useredit.component.css']
})
export class UsereditComponent implements OnInit {

  user: User;
  submitResult: string;
  constructor(private location: Location,
    private route: Router,
    private activatedRoute: ActivatedRoute,
    private userService: TestService) { }

  ngOnInit() {
    const id = +this.activatedRoute.snapshot.paramMap.get('id');
    this.userService.getUser(id).subscribe(user => this.user = user);
  }
  onSubmit(ngform: NgForm) {
    this.submitResult = JSON.stringify(ngform.value);
  }
  back() {
    this.location.back();
  }
}
